package com.elh.nio.test;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author liulei
 **/
public class Server {

    public static void main(String[] args) throws IOException {
        char[] charArray = new char[3];
        ServerSocket serverSocket = new ServerSocket(6666);
        System.out.println("start ===>");
        Socket socket = serverSocket.accept();
        System.out.println("end ===>");
        InputStream inputStream = socket.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        int length = 0;
        while((length = inputStreamReader.read(charArray)) != -1){
            String content = new String(charArray,0,length);
            System.out.println("content ===>" + content);
        }
        System.out.println("read end " + System.currentTimeMillis());

    }

}
